package com.jiangyg.mall.admin.controller;

import com.jiangyg.mall.admin.service.ResourceService;
import com.jiangyg.mall.authz.UserInfoHolder;
import com.jiangyg.mall.core.support.restful.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 类描述：权限相关控制器
 *
 * @author jiangyg
 * @version 2.0
 * @date 2020-05-31
 */
@RestController
public class AuthController {

    private final ResourceService resourceService;

    @Autowired
    public AuthController(ResourceService resourceService) {
        this.resourceService = resourceService;
    }

    /**
     * 功能描述：查询登录用户的授权菜单
     *
     * @param request 请求
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/menu")
    public Result<Object> menu(HttpServletRequest request) throws Exception {
        final Long userId = UserInfoHolder.loginUserId();
        return Result.ok(resourceService.selectUserGrantedMenu(userId));
    }

}
